﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VehicleScale.Models;

namespace VehicleScale.EntityMappers
{
    public class CompanyInfoMapper
    {
        #region Methods With Relation
        public static CompanyInfoModel ToModel(CompanyInfo entity)
        {
            if (entity == null) return null;
            CompanyInfoModel model = new CompanyInfoModel()
            {
                CompanyName = entity.CompanyName,
                Address = entity.Address,
                Telephone = entity.Telephone,
                FaxNumber = entity.FaxNumber,
                TaxCode = entity.TaxCode
            };
            if (entity.LogoImage != null)
                model.LogoByte = entity.LogoImage.ToArray();

            return model;

        }

        public static CompanyInfo ToEntity(CompanyInfo entity, CompanyInfoModel model)
        {
            if (model == null) return null;
            entity.CompanyName = model.CompanyName;
            entity.Address = model.Address;
            entity.Telephone = model.Telephone;
            entity.FaxNumber = model.FaxNumber;
            entity.TaxCode = model.TaxCode;
            if(model.LogoByte != null)
                entity.LogoImage = new System.Data.Linq.Binary(model.LogoByte);

            return entity;
        }
        #endregion
    }
}
